package com.lin.learning.questionmanagement.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lin.learning.questionmanagement.mapper.UserMapper;
import com.lin.learning.questionmanagement.service.LoginService;
import com.our.learning.infrastructure.po.Teacher;
import com.our.learning.infrastructure.po.User;
import com.our.learning.infrastructure.pojo.Response;
import com.our.learning.infrastructure.pojo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : PanicLin
 * @date : 2023-06-17
 */
@RestController
public class LoginController {

    @Autowired
    private final LoginService loginService;

    @Autowired
    private UserMapper userMapper;

    public String getTypeById(Integer id){
        LambdaQueryWrapper<User> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getId,id);
        User user=userMapper.selectOne(queryWrapper);
        return user.getType();
    }

    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }


    @RequestMapping("/test")
    public String test(){
        return "test";
    }

    @RequestMapping("/login")
    public ResponseResult userLogin(@RequestBody User user){
        return loginService.userLogin(user);
    }

    @PostMapping("/logout")
    public ResponseResult logout(){
        return loginService.logout();
    }
}
